<table width="100%"><tr><td width="20%">
<a href="../index.html">&lt; index</a><br />
<a href="index.html">&lt; 15. Heightmap toolkit</a><br />
<a href="heightmap_modify.html">&lt; 15.3 Modifying the heightmap</a>
</td><td width="60%">
<p align="center">
=====================================<br />
15.4 Reading data from the heightmap<br />
=====================================<br />
</p></td><td width="20%">
<a href="heightmap_delete.html">&gt; 15.5 Destroying a heightmap</a>
</td></tr></table>
<style type="text/css">
.code { color:#444444; background-color:#EEEEEE;}
pre { color:#444444; background-color:#EEEEEE;}
table.param td { border : 1px solid #000000; }
th { background-color: #44BBFF; color: #FFFFFF }
table.none td { border : 0 }
</style>
<br />
Those functions return raw or computed information about the heightmap.<br />
<a href="#15.4.1">15.4.1 Get the value of a cell<br /></a>
<a href="#15.4.2">15.4.2 Interpolate the height<br /></a>
<a href="#15.4.3">15.4.3 Get the map slope<br /></a>
<a href="#15.4.4">15.4.4 Get the map normal<br /></a>
<a href="#15.4.5">15.4.5 Count the map cells inside a height range<br /></a>
<a href="#15.4.6">15.4.6 Check if the map is an island<br /></a>
<a href="#15.4.7">15.4.7 Get the map min and max values<br /></a>
<br />
<a name="15.4.1"></a><h4>15.4.1 Get the value of a cell</h4>
This function returns the height value of a map cell.<br />
<p class="code"><pre>
C++ : float TCODHeightmap::getValue(int x, int y) const
C   : float TCOD_heightmap_get_value(const TCOD_heightmap_t *hm, int x, int y)
Py  : heightmap_get_value(hm,  x, y)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>hm</td><td>In the C version, the address of the heightmap struct returned by the <a href="heightmap_init.html">creation function</a>.</td></tr>
<tr><td>x,y</td><td>Coordinates of the map cell.<br />0 &lt;= x &lt; map width<br />0 &lt;= y &lt; map height</td></tr>
</table>
<hr />
<a name="15.4.2"></a><h4>15.4.2 Interpolate the height</h4>
This function returns the interpolated height at non integer coordinates.<br />
<p class="code"><pre>
C++ : float TCODHeightmap::getInterpolatedValue(float x, float y) const
C   : float TCOD_heightmap_get_interpolated_value(const TCOD_heightmap_t *hm, float x, float y)
Py  : heightmap_get_interpolated_value(hm, x, y)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>hm</td><td>In the C version, the address of the heightmap struct returned by the <a href="heightmap_init.html">creation function</a>.</td></tr>
<tr><td>x,y</td><td>Coordinates of the map cell.<br />0 &lt;= x &lt; map width<br />0 &lt;= y &lt; map height</td></tr>
</table>
<hr />
<a name="15.4.3"></a><h4>15.4.3 Get the map slope</h4>
This function returns the slope between 0 and PI/2 at given coordinates.<br />
<p class="code"><pre>
C++ : float TCODHeightmap::getSlope(int x, int y) const
C   : float TCOD_heightmap_get_slope(const TCOD_heightmap_t *hm, int x, int y)
Py  : heightmap_get_slope(hm, x, y)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>hm</td><td>In the C version, the address of the heightmap struct returned by the <a href="heightmap_init.html">creation function</a>.</td></tr>
<tr><td>x,y</td><td>Coordinates of the map cell.<br />0 &lt;= x &lt; map width<br />0 &lt;= y &lt; map height</td></tr>
</table>
<hr />
<a name="15.4.4"></a><h4>15.4.4 Get the map normal</h4>
This function returns the map normal at given coordinates.<br />
<p class="code"><pre>
C++ : void TCODHeightmap::getNormal(float x, float y,float n[3], float waterLevel=0.0f) const
C   : void TCOD_heightmap_get_normal(const TCOD_heightmap_t *hm, float x, float y, float n[3], float waterLevel)
Py  : heightmap_get_normal(hm, x, y, waterLevel) # returns nx,ny,nz
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>hm</td><td>In the C version, the address of the heightmap struct returned by the <a href="heightmap_init.html">creation function</a>.</td></tr>
<tr><td>x,y</td><td>Coordinates of the map cell.<br />0 &lt;= x &lt; map width<br />0 &lt;= y &lt; map height</td></tr>
<tr><td>n</td><td>The function stores the normalized normal vector in this array.</td></tr>
<tr><td>waterLevel</td><td>The map height is clamped at waterLevel so that the sea is flat.</td></tr>
</table>
<hr />
<a name="15.4.5"></a><h4>15.4.5 Count the map cells inside a height range</h4>
This function returns the number of map cells which value is between min and max.<br />
<p class="code"><pre>
C++ : int TCODHeightmap::countCells(float min,float max) const
C   : int TCOD_heightmap_count_cells(const TCOD_heightmap_t *hm, float min, float max)
Py  : heightmap_count_cells(hm, min, max)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>hm</td><td>In the C version, the address of the heightmap struct returned by the <a href="heightmap_init.html">creation function</a>.</td></tr>
<tr><td>min,max</td><td>Only cells which value is &gt;=min and &lt;= max are counted.</td></tr>
</table>
<hr />
<a name="15.4.6"></a><h4>15.4.6 Check if the map is an island</h4>
This function checks if the cells on the map border are below a certain height.<br />
<p class="code"><pre>
C++ : bool TCODHeightmap::hasLandOnBorder(float waterLevel) const
C   : bool TCOD_heightmap_has_land_on_border(const TCOD_heightmap_t *hm, float waterLevel)
Py  : heightmap_has_land_on_border(hm, waterLevel)
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>hm</td><td>In the C version, the address of the heightmap struct returned by the <a href="heightmap_init.html">creation function</a>.</td></tr>
<tr><td>waterLevel</td><td>Return true only if no border cell is &gt; waterLevel.</td></tr>
</table>
<hr />
<a name="15.4.7"></a><h4>15.4.7 Get the map min and max values</h4>
This function calculates the min and max of all values inside the map.<br />
<p class="code"><pre>
C++ : void TCODHeightmap::getMinMax(float *min, float *max) const
C   : void TCOD_heightmap_get_minmax(const TCOD_heightmap_t *hm, float *min, float *max)
Py  : heightmap_get_minmax(hm) # returns min,max
</pre></p>
<table class="param">
<tr><th>Parameter</th><th>Description</th></tr>
<tr><td>hm</td><td>In the C version, the address of the heightmap struct returned by the <a href="heightmap_init.html">creation function</a>.</td></tr>
<tr><td>min, max</td><td>The min and max values are returned in these variables.</td></tr>
</table>
<hr />
